//
//  QuotesViewController.m
//  AAIM
//
//  Created by 远的小布丁 on 2020/1/19.
//  Copyright © 2020 AAIM. All rights reserved.
//

#import "QuotesViewController.h"
#import "CenterTableViewCell.h"
#import "ServiceViewController.h"

@interface QuotesViewController ()<UIWebViewDelegate,UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UIWebView * contentWebView;
@property (nonatomic,strong)NSString * quotesUrl;
@property (nonatomic,strong)UITableView * discoverTableView;
@property (nonatomic,strong)NSArray * dataAry;
@end

@implementation QuotesViewController


- (void)viewDidLoad {
    [super viewDidLoad];
   
    _quotesUrl = [[NSUserDefaults standardUserDefaults] objectForKey:@"quotesUrl"];

//         [self.view addSubview:self.contentWebView];
//        if (![_quotesUrl containsString:@"https://"]) {
//               [self.contentWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://%@",_quotesUrl]]]];
//           }else{
//               [self.contentWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",_quotesUrl]]]];
//           }
//
//           self.gk_navigationItem.hidesBackButton = YES;
//           UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//           [backBtn setImage:[UIImage imageNamed:@"icon-返回键"] forState:UIControlStateNormal];
//           [backBtn addTarget:self action:@selector(backacrion) forControlEvents:UIControlEventTouchUpInside];
//           [backBtn sizeToFit];
//           backBtn.frame = CGRectMake(0, 0, 44, 44);
//           backBtn.jk_touchAreaInsets  = UIEdgeInsetsMake(10, 10, 10, 10);
//           UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
//           self.gk_navLeftBarButtonItem = backItem;

            _dataAry = @[@[@{@"imageStr":@"发现",@"titleStr":@"关注圈"}],@[@{@"imageStr":@"扫一扫",@"titleStr":@"扫一扫"}],@[@{@"imageStr":@"学习中心",@"titleStr":@"学习中心"},@{@"imageStr":@"咨询活动",@"titleStr":@"咨询活动"},@{@"imageStr":@"人脉关系",@"titleStr":@"人脉关系"}],@[@{@"imageStr":@"客服中心",@"titleStr":@"客服中心"}]];
            [self.view addSubview:self.discoverTableView];

   
}

- (void)backacrion{
    
    if ([self.contentWebView canGoBack]) {
        
        /// 网页可以返回 就进行网页返回
        
        [self.contentWebView goBack];
        
    }else{
        
        [self.view resignFirstResponder];
        
        /// 网页返回到首页了 返回不了了 这时候我们的控制器返回
        
        [self.navigationController popViewControllerAnimated:YES];
        
    }
    
}


-(void)webViewDidStartLoad:(UIWebView *)webView
{
    [self showAlwaysTipHudWithText:@"加载中，请稍等"];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    [self hideHud];
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [self showTipHudWithText:@"网络错误，稍后再试"];
}

- (UIWebView *)contentWebView{
    if (!_contentWebView) {
        _contentWebView = [[UIWebView alloc]initWithFrame:CGRectMake(0, self.gk_navigationBar.bottom, kScreenWidth, kScreenHeight-self.gk_navigationBar.bottom)];
        _contentWebView.delegate = self;
    }
    return _contentWebView;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _dataAry.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [_dataAry[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CenterTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"DiscoverCell"];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"CenterTableViewCell" owner:self options:nil] firstObject];
    }
    cell.dataDic = _dataAry[indexPath.section][indexPath.row];
    cell.otherLabel.hidden = YES;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 3&& indexPath.row == 0) {
        ServiceViewController * serviceVC = [[ServiceViewController alloc]init];
        serviceVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:serviceVC animated:YES];
    }else if (indexPath.section == 1){
        
    }
}



- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 0.1f;
    }
    return 8.f;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}


-(UITableView *)discoverTableView{
    if (!_discoverTableView) {
        _discoverTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, self.gk_navigationBar.bottom, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
        _discoverTableView.delegate= self;
        _discoverTableView.dataSource = self;
        _discoverTableView.tableHeaderView = [UIView new];
        _discoverTableView.tableFooterView = [UIView new];
        _discoverTableView.backgroundColor = KHEXCOLOR(@"#F4F4F4");
        _discoverTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _discoverTableView.rowHeight = 49.f;
    }
    return _discoverTableView;
}

@end
